// /**------------------------- 内容分析 -----------------------*/
/**---------- 时间选择器 ----------*/
layui.use('laydate', function () {
    let laydate = layui.laydate;
    //执行一个laydate实例
    laydate.render({
        elem: '#test3', //指定元素
        theme: '#337AB7',
        type: 'datetime'
    });
});
/**---------- 时间选择器 ----------*/
layui.use('laydate', function () {
    let laydate = layui.laydate;
    //执行一个laydate实例
    laydate.render({
        elem: '#test4', //指定元素
        theme: '#337AB7',
        type: 'datetime'
    });
});
/**---------- 空间分析 表单 ----------*/
layui.use('form', function () {
    let form = layui.form;
    //监听提交
    form.on('submit(formDemo1)', function () {
        axios
            .post('/d/broadcast/chart', msg)
            .then(function (response) {
                let category = response.data.category;
                chart_category(category);
            });
        return false;
    });
});
/**---------- 内容分析 表单 ----------*/
layui.use(['form', 'layer'], function () {
    let form = layui.form;

    //监听提交
    form.on('submit(formDemo2)', function (data) {
        let msg = JSON.stringify(data.field);
        // alert(msg);
        axios
            .post('/d/broadcast/chart', msg)
            .then(function (response) {
                layer.alert('数据更新成功');
                let category = response.data.category;
                chart_category(category);
            });
        // axios
        //     .post('/d',msg)
        // document.getElementById
        return false;
    });
});
/**---------- 时间选择器 ----------*/
var start;
var end;
layui.use('slider', function () {
    let slider = layui.slider;
    //渲染
    let max = 365;
    slider.render({
        elem: '#slideTest1',  //绑定元素,
        type: 'vertical',
        range: true,
        height: 380,
        max: max,
        value: [0, max],
        setTips: function (value) {
            return getDay(max - value);
        },
        change: function (value) {
            $('#text1').html('开始日期: ' + getDay(max - value[1]));
            $('#text2').html('结束日期: ' + getDay(max - value[0]));
            start = getDay(max - value[1]);
            end = getDay(max - value[0]);
            // alert(start);
        }
    });
});

//获得多少天之前的日期 列如2018-01-01
function getDay(day) {
    let today = new Date(2018, 12, 1);
    let targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
    today.setTime(targetday_milliseconds); //注意，这行是关键代码
    let tYear = today.getFullYear();
    let tMonth = today.getMonth();
    let tDate = today.getDate();
    tMonth = tMonth + 1;
    return tYear + "/" + tMonth + "/" + tDate;
}


var btn = document.getElementById('sub');
// start = start.innerHTML;
// end = end.innerHTML;
btn.onclick = function () {
    let params = {
        'start': start,
        'end': end
    };
    // alert(params.start);
    axios
        .post('/d/broadcast/heat', params)
        .then(function (response) {
            let location_list = response.data.ret;
            heatdata = [];
            // alert(location_list);
            for (let item in location_list) {
                if (!location_list.hasOwnProperty(item)) continue;
                let location = location_list[item].split(',');
                heatdata.push({
                    lng: location[0],
                    lat: location[1],
                    count: 10
                })
            }
            // alert(heatdata);
            // layer.setData(heatdata);
            ResetHeat();
        })
};